package com.example.test;

import java.util.ArrayList;
import java.util.List;

public class HashCodeGenerate02 {
    private static String[] base = new String[]{"Aa", "BB"};

    /* 生成 2^n 个值 */
    public static List<String> generateN(int n) {
        if (n <= 0) return null;

        List<String> list = generateOne(null);
        for (int i = 1; i < n; ++i) {
            list = generateOne(list);
        }

        return list;
    }

    /* 生成 2 个 hashcode 相同的值 */
    public static List<String> generateOne() {
        return generateOne(null);
    }

    public static List<String> generateOne(List<String> strList) {
        if ((null == strList) || (0 == strList.size())) {
            strList = new ArrayList<String>();
            for (int i = 0; i < base.length; ++i) {
                strList.add(base[i]);
            }

            return strList;
        }

        List<String> result = new ArrayList<String>();

        for (int i = 0; i < base.length; ++i) {
            for (String str : strList) {
                result.add(base[i] + str);
            }
        }

        return result;
    }

    public static void main(String[] args) {
        System.out.println("generateOne(): " + generateOne());
        System.out.println("generateN(2): " + generateN(2));
        System.out.println("generateN(3): " + generateN(3));
        System.out.println("generateN(4): " + generateN(4));
        System.out.print("generateN(3) 的hashcode：" + "\t");
        List<String> list = generateN(3);
        for (String str : list) {
            System.out.print(str.hashCode() + "\t");
        }
    }
}
